package pl.streamsoft.currencyApp.model;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "CURRENCIES")
@SecondaryTable(name = "CURRENCY_INFO")
@NamedQueries({
		@NamedQuery(name = "Currency.getCurrenciesByDateOfPublication", query = "from Currency where dateOfPublication = :dateOfPublication"),
		@NamedQuery(name = "Currency.getExistingDatesFromTo", query = "select dateOfPublication from Currency where dateOfPublication >= :fromDate and dateOfPublication <= :toDate"),
		@NamedQuery(name = "Currency.getCurrenciesByDateFromTo", query = "from Currency where dateOfPublication >= :fromDate and dateOfPublication <= :toDate"),
		@NamedQuery(name = "Currency.getCurrenciesByCode", query = "from Currency where dateOfPublication = :dateOfPublication and currencyCode = :codeName"),
		@NamedQuery(name = "Currency.getCurrenciesByName", query = "from Currency where dateOfPublication = :dateOfPublication and name = :currencyName"),
		@NamedQuery(name = "Currency.getCurrenciesByKeyWord", query = "from Currency where dateOfPublication = :dateOfPublication and (name like concat('%', :keyWord, '%') or currencyCode like concat('%', :keyWord, '%'))"),
		@NamedQuery(name = "Currency.getCurrenciesByMinValue", query = "from Currency where dateOfPublication = :dateOfPublication and averageRate >= :minValue"),
		@NamedQuery(name = "Currency.getCurrenciesByMinAndMaxValue", query = "from Currency where dateOfPublication = :dateOfPublication and averageRate >= :minValue and averageRate <= :maxValue") })
public class Currency {
	// (:keyWord like str(c.name) or :keyWord like str(c.currencyCode))"),
	@Id
	@Column(name = "CURRENCY_ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long currencyId;

	@Column(name = "CURRENCY_NAME", table = "CURRENCY_INFO")
	private String name;

	@Column(name = "CURRENCY_CONVERTED", table = "CURRENCY_INFO")
	private int converter;

	@Column(name = "CURRENCY_CODE", table = "CURRENCY_INFO")
	private String currencyCode;

	@Column(name = "CURRENCY_VALUE")
	private BigDecimal averageRate;

	@Column(name = "CURRENCY_DATE_OF_PUBLICATION")
	@Temporal(TemporalType.DATE)
	private Date dateOfPublication;

	public Currency() {
	}

	public Currency(String name, String code, BigDecimal value) {
		this.name = name;
		this.currencyCode = code;
		this.averageRate = value;
	}

	public BigDecimal getAverageRate() {
		return averageRate;
	}

	public void setAverageRate(BigDecimal averageRate) {
		this.averageRate = averageRate;
	}

	public Date getDateOfPublication() {
		return dateOfPublication;
	}

	public void setDateOfPublication(Date dateOfPublication) {
		this.dateOfPublication = dateOfPublication;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getConverter() {
		return converter;
	}

	public void setConverter(int converter) {
		this.converter = converter;
	}

	public String getCurrencyCode() {
		return currencyCode;
	}

	public void setCurrencyCode(String currencyCode) {
		this.currencyCode = currencyCode;
	}

	public long getId() {
		return currencyId;
	}

	public void setId(long id) {
		this.currencyId = id;
	}
}
